﻿<div class="container_12">
    <div class="grid_6">
        <div class="module">
            <h2>
                <span></span>
            </h2>
            <div class="module-body">
                <fieldset>
                    <input type="radio" name="radio_choice" id="choice1" onclick="choice_function();" checked="checked">&nbsp;&nbsp;
                    <input id="txt_account" name="txt_account" type="text" class="input-medium" />&nbsp;&nbsp;<input
                        class="submit-green" id="btn_account" name="btn_account" type="button" value="Tra cứu" />

                </fieldset>
                <input type="radio" name="radio_choice" id="choice2" onclick="choice_function();">&nbsp;&nbsp;
                Đơn vị:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.donvi != null)
                {                               
                    @Html.DropDownList("quan_huyen_id", ViewBag.donvi as SelectList, "---Chọn đơn vị---", new { style = "width: 38.8%",@disabled = "disabled" })                               
                }
                <br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Xã phường:&nbsp;
                @if (ViewBag.khuvuc == null)
                {    
                    @Html.DropDownList("xa_phuong_id", Enumerable.Empty<SelectListItem>(), "---Chọn Xã phường---", new { style = "width: 39%",@disabled = "disabled" })
                }
                else
                {
                    @Html.DropDownList("xa_phuong_id", ViewBag.khuvuc as SelectList, "---Chọn Xã phường---", new { style = "width: 39%",@disabled = "disabled" })
                }
                <br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tổ dân phố:&nbsp;
                @if (ViewBag.todanpho == null)
                {    
                    @Html.DropDownList("todanpho_id", Enumerable.Empty<SelectListItem>(), "---Chọn Tổ dân phố---", new { style = "width: 38.5%",@disabled = "disabled" })
                }
                else
                {
                    @Html.DropDownList("todanpho_id", ViewBag.todanpho as SelectList, "---Chọn Tổ dân phố---", new { style = "width: 38.5%",@disabled = "disabled" })
                }
                <br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dslam:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.dslam == null)
                {    
                    @Html.DropDownList("system_id", Enumerable.Empty<SelectListItem>(), "---Chọn Dslam---", new { style = "width: 38.5%",@disabled = "disabled" })
                }
                else
                {
                    @Html.DropDownList("system_id", ViewBag.dslam as SelectList, "---Chọn Dslam---", new { style = "width: 38.5%",@disabled = "disabled" })
                }
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cổng:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @if (ViewBag.cong == null)
                {    
                    @Html.DropDownList("cong", Enumerable.Empty<SelectListItem>(), "---Chọn Cổng---", new { style = "width: 38.7%",@disabled = "disabled" })
                }
                else
                {
                    @Html.DropDownList("cong", ViewBag.cong as SelectList, "---Chọn Cổng---", new { style = "width: 39%",@disabled = "disabled" })
                }&nbsp;<input class="submit-green" id="btn_cong" name="btn_cong" type="button" value="Tra cứu" />
                <br />
                <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="service_radio" id="internet_radio" checked="checked"/>Internet &nbsp;&nbsp;
                <input type="radio" name="service_radio" id="mytv_radio"/>My TV &nbsp;&nbsp;
                <input class="submit-green" id="btn_tao" name="btn_tao" type="button" value="Tạo" />
                <text id="txt_result" name="txt_result"></text>
                
            </div>
        </div>
        <!-- module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_6 -->
    <!-- To-do list -->
    <div class="grid_6">
        <div class="module">
            <h2>
                <span>Kết quả tra cứu</span></h2>
            <div class="module-body">
                <text id="SNR_textbox" name="SNR_textbox"></text>
            </div>
        </div>
        <!-- module -->
        <div style="clear: both;">
        </div>
    </div>
    <!-- End .grid_6 -->
    <div style="clear: both;">
    </div>
</div>
<script type="text/javascript">
    function reloadpage(data) {
        if (data.indexOf("html") > -1) {
            window.location.reload();
            return true;
        }
        else
            return false;
    }
    function choice_function() {
        if (document.getElementById('choice1').checked) {
            document.getElementById('quan_huyen_id').disabled = true;
            document.getElementById('xa_phuong_id').disabled = true;
            document.getElementById('todanpho_id').disabled = true;
            document.getElementById('system_id').disabled = true;
            document.getElementById('cong').disabled = true;
            document.getElementById('txt_account').disabled = false;
        }
        if (document.getElementById('choice2').checked) {
            document.getElementById('quan_huyen_id').disabled = false;
            document.getElementById('xa_phuong_id').disabled = false;
            document.getElementById('todanpho_id').disabled = false;
            document.getElementById('system_id').disabled = false;
            document.getElementById('cong').disabled = false;
            document.getElementById('txt_account').disabled = true;
        }
    }
    $("#btn_account").click(function () {
        if (document.getElementById("txt_account").value.length < 4) {
            alert('Account phải có nhiều hơn 3 ký tự');
            return;
        }
        $("#SNR_textbox").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("GetSNRJSon", "DslamPort")',
            data: { account: document.getElementById("txt_account").value, cong: '', system_id: '', option: '11' },
            success: function (data) {

                if (reloadpage(data)) return;
                $("#SNR_textbox").html(data);
            }
        })

    });
    $("#btn_cong").click(function () {
        if (document.getElementById("cong").value == "") {
            alert("Phải chọn cổng");
            return;
        }
        $("#SNR_textbox").html("Vui lòng chờ...");
        $.ajax({
            type: "POST",
            url: '@Url.Action("GetSNRJSon", "DslamPort")',
            data: { account: '', cong: document.getElementById("cong").value, system_id: document.getElementById("system_id").value, option: '11' },
            success: function (data) {
                if (reloadpage(data)) return;
                $("#SNR_textbox").html(data);
            }
        })
    });
    $("#btn_tao").click(function () {
        var x;
        if (document.getElementById('internet_radio').checked)
            x = "4";
        if (document.getElementById('mytv_radio').checked)
            x = "16";
        if (document.getElementById('choice1').checked) {
            if (document.getElementById("txt_account").value.length < 4) {
                alert('Account phải có nhiều hơn 3 ký tự');
                return;
            }
            $("#txt_result").html("Vui lòng chờ...");
            $.ajax({
                type: "POST",
                url: '@Url.Action("Create_Account_In_PortJSon", "DslamPort")',
                data: { account: document.getElementById("txt_account").value, cong: '', system_id: document.getElementById("system_id").value, option: x },
                success: function (data) {
                    if (reloadpage(data)) return;
                    $("#txt_result").html(data);
                }
            })
        }
        if (document.getElementById('choice2').checked) {
            if (document.getElementById("cong").value == "") {
                alert("Phải chọn cổng");
                return;
            }
            $("#txt_result").html("Vui lòng chờ...");
            $.ajax({
                type: "POST",
                url: '@Url.Action("Create_Account_In_PortJSon", "DslamPort")',
                data: { account: '', cong: document.getElementById("cong").value, system_id: document.getElementById("system_id").value, option: x },
                success: function (data) {
                    if (reloadpage(data)) return;
                    $("#txt_result").html(data);
                }
            })
        }
    });
    $("#quan_huyen_id").change(function () {
        $("#todanpho_id").html("<option value=''>---Chọn Tổ dân phố---</option>");
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            async: false,
            url: '@Url.Action("getDslamJson", "DslamPort")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#quan_huyen_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getKhuvucJson", "DslamPort")',
            data: { quan_huyen_id: $("#quan_huyen_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Xã phường---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#xa_phuong_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $("#system_id").html("<option value=''>---Chọn Dslam---</option>");
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getTodanphoJson", "DslamPort")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "ten" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Tổ dân phố---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#todanpho_id").html(items.join(' '));
            }
        })
    });
    $("#xa_phuong_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByKhuvucJson", "DslamPort")',
            data: { xa_phuong_id: $("#xa_phuong_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });
    $("#todanpho_id").change(function () {
        $("#cong").html("<option value=''>---Chọn cổng---</option>")
        $.ajax({
            type: "POST",
            url: '@Url.Action("getDslamByTodanphoJson", "DslamPort")',
            data: { todanpho_id: $("#todanpho_id > option:selected").attr("value"), Order: "name" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn Dslam---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#system_id").html(items.join(' '));
            }
        })
    });

    $("#system_id").change(function () {
        $.ajax({
            type: "POST",
            url: '@Url.Action("getcongJson", "DslamPort")',
            data: { system_id: $("#system_id > option:selected").attr("value"), Order: "cong" },
            success: function (data) {
                if (data.indexOf("html") > -1)
                    window.location.reload();
                var items = [];
                items.push("<option value=''>---Chọn cổng---</option>");
                $.each(data, function () {
                    items.push("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                $("#cong").html(items.join(' '));
            }
        })
    });
</script>
